package com.atguigu.async;

import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;

public class FutureDemo03 {
    public static void main(String[] args) throws Exception {
        runAsync1();
        runAsync2();
    }
    //发起一个异步请求
    public static void runAsync1() {
        CompletableFuture.runAsync(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName()+"你好runAsync1");
            }
        }).whenComplete(new BiConsumer<Void, Throwable>() {
            //类似于vue里面发起异步请求之后的then方法
            @Override
            public void accept(Void acceptVal, Throwable throwable) {
                System.out.println(Thread.currentThread().getName()+"获取上面执行之后的返回值1"+acceptVal);
            }
        });
    }
    //发起一个异步请求
    public static void runAsync2() {
        CompletableFuture.runAsync(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName()+"你好runAsync2");
            }
        }).whenCompleteAsync(new BiConsumer<Void, Throwable>() {
            //类似于vue里面发起异步请求之后的then方法
            @Override
            public void accept(Void acceptVal, Throwable throwable) {
                System.out.println(Thread.currentThread().getName()+"获取上面执行之后的返回值2"+acceptVal);
            }
        });
    }


}
